#include<stdio.h>
#include<stdlib.h>

int main()
{
     while(1)
     {
         int n;
         scanf("%d", &n);
         if( n == 0 )
              break;
         int *N = (int *)malloc(sizeof(int) * n);
         
         int i = 0;
         int j = 0;
         int all_neg = 1;
         for(; i < n; ++i)
         {
               scanf("%d", N + i);
               if (N[i] >= 0)
                  all_neg = 0;
         }
         
         if (all_neg == 1)
               printf("%d %d %d\n", 0, N[0], N[n-1]);
         else
         {
               int max_i = -1, max_j = -1;
               int max = -1;
               for (i = 0; i < n; ++i)
               {
                   int sum = 0;
                   for (j = i; j < n; ++j)
                   {
                           sum += N[j];
                           if(sum > max)
                           {
                                  max = sum;
                                  max_i = i;
                                  max_j = j;
                           }
                   }
               }
               
               printf("%d %d %d\n", max, N[max_i], N[max_j]);
         }           
     }
     
     system("pause");
     return 0;    
}
